<div class="events <?php echo $eventCallerName;?> <?php echo $view_type;?>">
<?php
uses("sanitize","Flay");
//debug($eventList);
foreach($eventList as $eventSingle)
{
	// collect are variables here
	$eventArr = array();

	$eventSingleId = $eventSingle['Event']['id'];
	$eventSlug = $eventSingle['Event']['slug'];

	$featuredClass = "";
	if ($eventCallerName == "populartw")
	{
		$featuredClass = "Y";
	}
	$img = $html->image($html->url($eventSingle['Event']['image'], true), array('alt'=>$eventSingle['Event']['title'],'thumb'=>cr('Thumbs.eventSmall'), 'height'=>cr('Thumbs.eventSmall.height'), 'width'=>cr('Thumbs.eventSmall.width')));
	
	$totalInterested = $eventSingle['Event']['interested_count'];
	//$totalInterested = $eventSingle['Event']['whosin_count'] + $eventSingle['Event']['soundscool_count'];
	$eventWhen = date("l, F, d H:i",strtotime($eventSingle['Event']['event_from']));
	if(isset($eventSingle['Event']['event_to']) && $eventSingle['Event']['event_to']!=null)
	{
		$eventWhen = $eventWhen . ' - ' . date("l, F, d H:i",strtotime($eventSingle['Event']['event_to']));
	}	
	$startDate = date("Ymd\THis\Z",strtotime($eventSingle['Event']['event_from']));
	$endDate = date("Ymd\THis\Z",strtotime($eventSingle['Event']['event_to']));
	$addToCalDate = $startDate . "/" . $endDate;
	
	$eventCategoryName = $html->link($eventSingle['EventCategory']['name'], $html->url(array('plugin' => 'events', 'controller' => 'events', 'action' => 'index', 'categoryId'=>$eventSingle['EventCategory']['id'], true)));
	
	$eventVenue = $eventSingle['Event']['venue'];
	$url = $html->url($eventSingle['Event']['viewUrl'], true);
	$title = $eventSingle['Event']['title'];
	$addedByLabel = __("Submitted By").":";
	
	$user = $eventSingle['User'];	
	$postedTime = $time->timeAgoInwords($eventSingle['Event']['created'],array('shortString'=>true));
	$eventArr = compact('featuredClass', 'img', 'url', 'title', 'addedByLabel', 'postedTime', 'totalInterested', 'eventWhen','eventVenue','addToCalDate','startDate','endDate','eventCategoryName');
	
	$userRatingHtml = "";
	$editorRatingHtml = "";
	
	$partialDescription = strip_tags($eventSingle['Event']['description']);
	$partialDescription = str_replace(array("\n"), "", $partialDescription);
	$partialDescription = Flay::fragment($partialDescription,150);
	//$partialDescription = $appHtml->flayText($partialDescription,150);
	
	$readReviewLink = '';
	if($eventSingle['Event']['comment_count'] > 0)
	{
		$readReviewTitle = __('Read Comments');
		//$readReviewLink = '/events/view/'.$eventSingleId;
		$readReviewLink = $html->url($eventSingle['Event']['viewUrl'], true);
		//adding div id of review here so it goes directly to reviews on view page.
		$linkId = "#event_comments";
		if(is_string($readReviewLink))
		{
			$readReviewLink .= "/$linkId";
		}else
		{
			$readReviewLink[] = $linkId;
		}
		$readReviewLink = $html->link($readReviewTitle, $readReviewLink, array('class' => 'read_comments'));
	}
	
	$reviewItTitle = __('Add Comment');
	//$reviewItLink = $html->url('/events/view/'.$eventSingle['Event']['id'].'/#event_comments');
	$reviewItLink = $html->url($eventSingle['Event']['viewUrl'].'/#event_comments', true);

	$viewPlansLink = null;
	$showEditLink = false;
	if(isset($isPosterEditAllowed) && ($isPosterEditAllowed==true) && (!is_null($loggedInUserId)) && $eventSingle['Event']['user_id']==$loggedInUserId){
		$showEditLink=true;
	}
	$showDeleteLink = false;
	if(isset($isPosterDeleteAllowed) && ($isPosterDeleteAllowed==true) && (!is_null($loggedInUserId)) && $eventSingle['Event']['user_id']==$loggedInUserId){
		$showDeleteLink=true;
	}
	$params = compact('viewPlansLink','userRatingHtml', 'editorRatingHtml', 'partialDescription', 'readReviewTitle', 'readReviewLink', 'reviewItTitle', 'reviewItLink', 'user', 'addedByLabel','eventSingleId','showEditLink','showDeleteLink','eventCallerName','eventSlug');
	$params['eventchild'] = $eventArr;
	echo $this->template('event_'.$view_type, $params);
}
?>
</div>
<div class="clear"></div>